﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using Lamex.Common;
using Lamex.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lamex.Library
{
   public class RetureControlStr
    {
        public static string GetstrWhere(GridView view, DataTable dt,int iRow)
        {
            string strWhere = "";
            foreach (DataRow dr in dt.Rows)
            {
                if (dr["MULT_DELETE_FLAG"].ToString().ToLower() == "true")
                {
                    return "";
                    strWhere += " and " + dr["WRITE_FIELD_NAME"].ToString() + " = '" + view.GetRowCellValue(iRow, dr["WRITE_FIELD_NAME"].ToString()).ToString() + "'";
                    
                }
            }

            return strWhere;
        }
        public static string GetstrEditWhere(Panel gc,GridView view,int iRow)
        {
            string strWhere = "";
            foreach (Control  c in gc.Controls)
            {
                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                   if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name+ " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";

                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";
                    
                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit uc = c as ucDateEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";
                }
                else if (c is ucDate)
                {
                    ucDate uc = c as ucDate;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";
                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";
                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    if (uc.UcIsFlterEditFlag == true)
                    {
                        if(view.GetRowCellDisplayText(iRow, uc.Name).ToString().ToLower()=="false")
                        {
                            strWhere += " and " + uc.Name + " = 0";
                        }
                        else
                        {
                            strWhere += " and " + uc.Name + " = 1";
                        }
                    }
                        
                }
            }

            return strWhere;
        }

        public static string GetstrEditWhere2(Panel gc,string isDateFlag,GridView view,int iRow)
        {
            string strWhere = "";
            foreach (Control c in gc.Controls)
            {
                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";

                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";

                }
                else if (c is ucDateEdit)
                {
                    if(isDateFlag=="true")
                    {
                        ucDateEdit uc = c as ucDateEdit;
                        if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        {
                            if (uc.UcMaxFlag.ToString().ToLower() == isDateFlag)
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + view.GetRowCellDisplayText(iRow, uc.Name) + "',120) ";
                            else
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + view.GetRowCellDisplayText(iRow, uc.Name) + "',120) ";
                        }
                    }
                    else
                    {
                        ucDateEdit uc = c as ucDateEdit;
                        if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        {
                            if (uc.UcMaxFlag.ToString().ToLower() == isDateFlag)
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'"+ view.GetRowCellDisplayText(iRow, uc.Name) + "',120) ";
                            else
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + view.GetRowCellDisplayText(iRow, uc.Name) + "',120) ";
                        }
                        
                    }
                    
                        
                }
                else if (c is ucDate)
                {
                    if (isDateFlag == "true")
                    {
                        ucDate uc = c as ucDate;
                        if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        {
                            if (uc.UcMaxFlag.ToString().ToLower() == isDateFlag)
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + Convert.ToDateTime(view.GetRowCellDisplayText(iRow, uc.Name)).ToString("yyyy-MM-dd") + "',120) ";
                            else
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + Convert.ToDateTime(view.GetRowCellDisplayText(iRow, uc.Name)).ToString("yyyy-MM-dd") + "',120) ";
                        }
                    }
                    else
                    {
                        ucDate uc = c as ucDate;
                        if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        {
                            if (uc.UcMaxFlag.ToString().ToLower() == isDateFlag)
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" +Convert.ToDateTime( view.GetRowCellDisplayText(iRow, uc.Name)).ToString("yyyy-MM-dd") + "',120) ";
                            else
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + Convert.ToDateTime(view.GetRowCellDisplayText(iRow, uc.Name)).ToString("yyyy-MM-dd") + "',120) ";
                        }

                    }


                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + view.GetRowCellDisplayText(iRow, uc.Name) + "'";

                }
            }

            return strWhere;
        }
        public static void SetControlValue(GridView view , Panel gc,int iRow,int iType)
        {
            foreach (Control c in gc.Controls)
            {

                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    if (uc.Tag.ToString() == "true")
                        uc.UcReadOnly = true;
                    if (view.GetRowCellValue(iRow, uc.Name)!=null)
                        uc.Text = view.GetRowCellValue(iRow, uc.Name).ToString();
                   
                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    if (uc.Tag.ToString() == "true")
                        uc.UcReadOnly = true;
                    if (view.GetRowCellValue(iRow, uc.Name) != null)
                        uc.Text = view.GetRowCellValue(iRow, uc.Name).ToString();
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    if (uc.Tag.ToString() == "true")
                    {
                        uc.UcReadOnly = true;
                        uc.UcProperties.Enabled = false;
                    }
                    if (view.GetRowCellValue(iRow, uc.Name) != null)
                        uc.UnEditValue = view.GetRowCellValue(iRow, uc.Name).ToString();
                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit uc = c as ucDateEdit;
                    if (uc.Tag.ToString() == "true")
                    {
                        uc.UcReadOnly = true;
                        uc.Enabled = false;
                    }
                    if (uc.UcMaxFlag == "true")
                        uc.UcEditValue = view.GetRowCellValue(iRow, uc.Name);
                    else
                        uc.UcEditValue = DateTime.Now;


                }
                else if (c is ucDate)
                {
                    ucDate uc = c as ucDate;
                    if (uc.Tag.ToString() == "true")
                    {
                        uc.UcReadOnly = true;
                        uc.Enabled = false;
                    }
                    if (uc.UcMaxFlag == "true")
                        uc.UcEditValue = view.GetRowCellValue(iRow, uc.Name);
                    else
                    //uc.UcEditValue = DateTime.Now.ToString("yyyy-MM-dd");
                    {
                        //if (iType == 0)
                        //    uc.UcEditValue = DateTime.Now.ToString("yyyy-MM-dd");
                        //else if (iType==1)
                            uc.UcEditValue = view.GetRowCellValue(iRow, uc.Name);
                        
                    }


                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    if (uc.Tag.ToString() == "true")
                        uc.UcReadOnly = true;
                    if (view.GetRowCellValue(iRow, uc.Name) != null)
                    {
                        bool isBool = false;
                        if (view.GetRowCellValue(iRow, uc.Name).ToString().ToLower() != "false")
                            isBool = true;
                        uc.isChecked = isBool;
                    } 
                }
                else if (c is ucPictrueEdit)
                {
                    ucPictrueEdit uc = c as ucPictrueEdit;
                    if (uc.Tag.ToString() == "true")
                        uc.UcReadOnly = true;
                    string str = view.GetRowCellValue(iRow, uc.Name).ToString();

                    if (!string.IsNullOrEmpty(str))
                        uc.LoadPicture((byte[])view.GetRowCellValue(iRow, uc.Name));
                    else
                        uc.ClearPicture();
                    

                }
                if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    if (uc.Tag.ToString() == "true")
                        uc.UcReadOnly = true;
                    if (view.GetRowCellValue(iRow, uc.Name) != null)
                        uc.Text = view.GetRowCellValue(iRow, uc.Name).ToString();

                }

            }
            foreach (Control c in gc.Controls)
            {

                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    if (uc.Tag.ToString().ToLower() == "true")
                        uc.UcReadOnly = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                    }
                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    if (uc.Tag.ToString().ToLower() == "true")
                        uc.UcReadOnly = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                    }
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    if (uc.Tag.ToString().ToLower() == "true")
                        uc.UcReadOnly = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                    }
                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit uc = c as ucDateEdit;
                    if (uc.Tag.ToString().ToLower() == "true")
                        uc.UcReadOnly = true;
                    
                }
                else if (c is ucDate)
                {
                    ucDate uc = c as ucDate;
                    if (uc.Tag.ToString().ToLower() == "true")
                        uc.UcReadOnly = true;

                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    if (uc.Tag.ToString().ToLower() == "true")
                        uc.UcReadOnly = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                    }
                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    if (uc.Tag.ToString().ToLower() == "true")
                        uc.UcReadOnly = true;

                }
                else if (c is ucPictrueEdit)
                {
                    ucPictrueEdit uc = c as ucPictrueEdit;
                    if (uc.Tag.ToString().ToLower() == "true")
                        uc.UcReadOnly = true;

                }

            }
        }

        public static void SetControlVaildValue(Panel gc)
        {
            foreach (Control c in gc.Controls)
            {

                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    uc.UcReadOnly = false;
                    uc.Text = "";
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    uc.UcReadOnly = false;
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    uc.Text = "";
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    uc.UcReadOnly = false;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    uc.Text = "";
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit uc = c as ucDateEdit;
                    uc.UcReadOnly = false;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.UcEditValue = DateTime.Now;
                    if (uc.UcMaxFlag == "true")
                        uc.UcEditValue = DateTime.MaxValue;
                    else
                        uc.UcEditValue = DateTime.Now;


                }
                else if (c is ucDate)
                {
                    ucDate uc = c as ucDate;
                    uc.UcReadOnly = false;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.UcEditValue = null ;
                    if (uc.UcMaxFlag == "true")
                        uc.UcEditValue = DateTime.MaxValue.ToString("yyyy-MM-dd");
                    //else
                    //    uc.UcEditValue = DateTime.Now.ToString("yyyy-MM-dd");


                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    uc.UcReadOnly = false;
                    uc.Text = "";
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    uc.UcReadOnly = false;
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    uc.isChecked = false;
                }
                else if (c is ucPictrueEdit)
                {
                    ucPictrueEdit uc = c as ucPictrueEdit;
                    uc.UcReadOnly = false;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.ClearPicture();

                }
            }
        }

        public static void IsEnableControl(Panel gc,bool IsBool)
        {
            foreach (Control c in gc.Controls)
            {

                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    uc.UcReadOnly = IsBool;
                    uc.Text = "";
                    
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    uc.UcReadOnly = IsBool;
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    uc.Text = "";
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    uc.UcReadOnly = IsBool;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    uc.Text = "";
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit uc = c as ucDateEdit;
                    uc.UcReadOnly = IsBool;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.UcEditValue = DateTime.Now;
                    if (uc.UcMaxFlag == "true")
                        uc.UcEditValue = DateTime.MaxValue;
                    else
                        uc.UcEditValue = DateTime.Now;


                }
                else if (c is ucDate)
                {
                    ucDate uc = c as ucDate;
                    uc.UcReadOnly = IsBool;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.UcEditValue = null;
                    //uc.UcEditValue = DateTime.Now.ToString("yyyy-MM-dd");
                    if (uc.UcMaxFlag == "true")
                        uc.UcEditValue = DateTime.MaxValue.ToString("yyyy-MM-dd");
                    


                }
                else if(c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    uc.UcReadOnly = IsBool;
                    uc.Text = "";

                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    uc.UcReadOnly = IsBool;
                    
                }
                else if (c is ucPictrueEdit)
                {
                    ucPictrueEdit uc = c as ucPictrueEdit;
                    uc.Enabled = true;

                }

            }
        }
        public static void SetControlEditValue(Panel gc)
        {
            foreach (Control c in gc.Controls)
            {

                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    if (uc.Tag.ToString() == "true")
                        uc.UcReadOnly = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                    }
                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    if (uc.Tag.ToString() == "true")
                        uc.UcReadOnly = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                    }
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    uc.UcReadOnly = false;
                    uc.Enabled = true;
                    uc.Text = "";
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                    }
                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit uc = c as ucDateEdit;
                    uc.UcReadOnly = true;
                    uc.Enabled = true;
                    uc.UcEditValue = DateTime.Now;

                }
                else if (c is ucDate)
                {
                    ucDate uc = c as ucDate;
                    uc.UcReadOnly = true;
                    uc.Enabled = true;
                    uc.UcEditValue = DateTime.Now.ToString("yyyy-MM-dd");

                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    uc.UcReadOnly = true;
                    uc.Enabled = true;
                    uc.UcEditValue = DateTime.Now;

                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    uc.UcReadOnly = true;

                }
                else if(c is ucPictrueEdit)
                {
                    ucPictrueEdit uc = c as ucPictrueEdit;
                    uc.UcReadOnly = false;
                    uc.Enabled = true;
                }
            }
        }
        /// <summary>
        /// 新建时用
        /// </summary>
        /// <param name="gc"></param>
        /// <param name="view"></param>
        /// <param name="iRow"></param>
        /// <returns></returns>
        public static string GetstrEditWhereInsert(Panel gc)
        {
            string strWhere = "";
            foreach (Control c in gc.Controls)
            {
                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";

                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";

                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit uc = c as ucDateEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";
                }
                else if (c is ucDate)
                {
                    ucDate uc = c as ucDate;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";
                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";
                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    if (uc.UcIsFlterEditFlag == true)
                        strWhere += " and " + uc.Name + " = '" + uc.isChecked + "'";
                }
            }

            return strWhere;
        }
        /// <summary>
        /// 逻辑2条件
        /// </summary>
        /// <param name="gc"></param>
        /// <param name="isDateFlag"></param>
        /// <param name="view"></param>
        /// <param name="iRow"></param>
        /// <returns></returns>
        public static string GetstrEditWhereInsert2(Panel gc, string isDateFlag)
        {
            string strWhere = "";
            foreach (Control c in gc.Controls)
            {
                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";

                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";

                }
                else if (c is ucDateEdit)
                {
                    if (isDateFlag == "true")
                    {
                        ucDateEdit uc = c as ucDateEdit;
                        if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        {
                            if (uc.UcMaxFlag.ToString().ToLower() == isDateFlag)
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + uc.Text + "',120) ";
                        }
                    }
                    else
                    {
                        ucDateEdit uc = c as ucDateEdit;
                        if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        {
                            if (uc.UcMaxFlag.ToString().ToLower() == isDateFlag)
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + uc.Text + "',120) ";
                            else
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + uc.Text + "',120) ";
                        }

                    }


                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        strWhere += " and " + uc.Name + " = '" + uc.Text + "'";

                }
                else if(c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    if (uc.UcIsFlterEditFlag == true)
                            strWhere += " and " + uc.Name + " = '" + uc.isChecked + "'";
                }

                else if (c is ucDate)
                {
                    if (isDateFlag == "true")
                    {
                        ucDate uc = c as ucDate;
                        if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        {
                            if (uc.UcMaxFlag.ToString().ToLower() == "true")
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + DateTime.MaxValue.ToString("yyyy-MM-dd") + "',120) ";
                            
                        }
                    }
                    else
                    {
                        ucDate uc = c as ucDate;
                        if (uc.UcFlterEditFlag.ToString().ToLower() == "true")
                        {
                            if (uc.UcMaxFlag.ToString().ToLower() == isDateFlag)
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + uc.Text + "',120) ";
                            else
                                strWhere += " and CONVERT(nvarchar(10)," + uc.Name + ", 120) = CONVERT(nvarchar(10),'" + uc.Text + "',120) ";
                        }

                    }


                }
            }

            return strWhere;
        }

        /// <summary>
        /// 禁用
        /// </summary>
        /// <param name="gc"></param>
        public static void SetControlReadOnlyValue(Panel gc)
        {
            foreach (Control c in gc.Controls)
            {

                if (c is ucTextEdit)
                {
                    ucTextEdit uc = c as ucTextEdit;
                    uc.UcReadOnly = true;
                    uc.Text = "";
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucComboBoxEdit)
                {
                    ucComboBoxEdit uc = c as ucComboBoxEdit;
                    uc.UcReadOnly = true;
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    uc.Text = "";
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucLookUpEdit)
                {
                    ucLookUpEdit uc = c as ucLookUpEdit;
                    uc.UcReadOnly = true;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    uc.Text = "";
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucDateEdit)
                {
                    ucDateEdit uc = c as ucDateEdit;
                    uc.UcReadOnly = true;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.UcEditValue = DateTime.Now;
                    if (uc.UcMaxFlag == "true")
                        uc.UcEditValue = DateTime.MaxValue;
                    else
                        uc.UcEditValue = DateTime.Now;


                }
                else if (c is ucDate)
                {
                    ucDate uc = c as ucDate;
                    uc.UcReadOnly = true;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.UcEditValue = DateTime.Now.ToString("yyyy-MM-dd");
                    if (uc.UcMaxFlag == "true")
                        uc.UcEditValue = DateTime.MaxValue.ToString("yyyy-MM-dd");
                    else
                        uc.UcEditValue = DateTime.Now.ToString("yyyy-MM-dd");
                }
                else if (c is ucMemoEdit)
                {
                    ucMemoEdit uc = c as ucMemoEdit;
                    uc.UcReadOnly = true;
                    uc.Text = "";
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    if (uc.UcUser.ToLower() == "true")
                    {
                        uc.Text = Loginer.CurrentUser.AccountName;
                        uc.UcReadOnly = true;
                    }
                }
                else if (c is ucCheckEdit)
                {
                    ucCheckEdit uc = c as ucCheckEdit;
                    uc.UcReadOnly = true;
                    uc.UcEnabled = true;
                    uc.Enabled = true;
                    uc.isChecked = false;
                }
                else if (c is ucPictrueEdit)
                {
                    ucPictrueEdit uc = c as ucPictrueEdit;
                    uc.UcReadOnly = false;
                    uc.Enabled = true;
                    uc.UcEnabled = true;
                    uc.ClearPicture();

                }
            }
        }
    }
}
